package service

import (
	"testing"
)

// TestGetVipTypeAndDays 测试会员类型和天数判断逻辑
func TestGetVipTypeAndDays(t *testing.T) {
	service := &WxPayService{}

	tests := []struct {
		name        string
		productName string
		expectedType uint
		expectedDays int
	}{
		{
			name:         "月会员",
			productName:  "健康月会员",
			expectedType: 1,
			expectedDays: 30,
		},
		{
			name:         "30天会员",
			productName:  "健康30天会员套餐",
			expectedType: 1,
			expectedDays: 30,
		},
		{
			name:         "季会员",
			productName:  "健康季会员",
			expectedType: 2,
			expectedDays: 90,
		},
		{
			name:         "90天会员",
			productName:  "健康90天会员套餐",
			expectedType: 2,
			expectedDays: 90,
		},
		{
			name:         "半年会员",
			productName:  "健康半年会员",
			expectedType: 3,
			expectedDays: 180,
		},
		{
			name:         "180天会员",
			productName:  "健康180天会员套餐",
			expectedType: 3,
			expectedDays: 180,
		},
		{
			name:         "年会员",
			productName:  "健康年会员",
			expectedType: 4,
			expectedDays: 365,
		},
		{
			name:         "365天会员",
			productName:  "健康365天会员套餐",
			expectedType: 4,
			expectedDays: 365,
		},
		{
			name:         "默认会员",
			productName:  "健康会员",
			expectedType: 1,
			expectedDays: 30,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			vipType, vipDays := service.getVipTypeAndDays(&tt.productName, nil)
			if vipType != tt.expectedType {
				t.Errorf("getVipTypeAndDays() vipType = %v, want %v", vipType, tt.expectedType)
			}
			if vipDays != tt.expectedDays {
				t.Errorf("getVipTypeAndDays() vipDays = %v, want %v", vipDays, tt.expectedDays)
			}
		})
	}
}

// TestContains 测试字符串包含函数
func TestContains(t *testing.T) {
	tests := []struct {
		name     string
		s        string
		substr   string
		expected bool
	}{
		{
			name:     "包含-小写",
			s:        "健康月会员",
			substr:   "月会员",
			expected: true,
		},
		{
			name:     "包含-大小写混合",
			s:        "健康Month会员",
			substr:   "month",
			expected: true,
		},
		{
			name:     "不包含",
			s:        "健康月会员",
			substr:   "年会员",
			expected: false,
		},
		{
			name:     "空字符串",
			s:        "健康会员",
			substr:   "",
			expected: true,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			result := contains(tt.s, tt.substr)
			if result != tt.expected {
				t.Errorf("contains() = %v, want %v", result, tt.expected)
			}
		})
	}
}